// pages/getGift/getGift.js
const app = getApp();
const util = require("../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 提交
   */
  submit:function(){
    let addressId = app.globalData.addressId
    if (addressId==null){
      wx.showToast({
        title: '请选择收货地址',
        icon: 'loading',
        duration: 2000
      });
      return;
    }
    let getTitleDetailUrl = app.globalData.baseUrl + "submitOrder"
    let data = {
      orderId: this.data.orderId,
      addressId: app.globalData.addressId,
      name: this.data.name
    }
    util.requestLoading(getTitleDetailUrl, data, "GET").then(res => {
      // console.log(res)
      if (res.data.status==0){
        wx.showToast({
          title: '提交成功',
          icon: 'success',
          duration: 2000
        });
        setTimeout(function () {
          wx.navigateTo({
            url: '/pages/index/index',
          })
        }, 2000)
      }
    })
  },

  /**
   * 地址
   */
  address:function(){
    wx.navigateTo({
      url: '/pages/personnal/myAddress/myAddress?choose='+0,
    })
  },

  /**
   * 选择产品颜色
   */
  changePic: function (event) {
    this.setData({
      slideColor: event.currentTarget.dataset.color,
      name: event.currentTarget.dataset.name
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let orderId = options.orderId
    this.setData({
      orderId: orderId
    })
    let getTitleDetailUrl = app.globalData.baseUrl + "getGift"
    let data = {
      orderId: orderId
    }
    util.requestLoading(getTitleDetailUrl, data, "GET").then(res => {
      // console.log(res)
      this.setData({
        picList:res.data.picList,
        giftName: res.data.giftName,
        needWangNum: res.data.needWangNum,
        number: res.data.number,
        gid: res.data.gid,
        slideColor: res.data.picList[0].color,
        name: res.data.picList[0].name
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      addressId: app.globalData.addressId
    })
    // console.log(app.globalData.addressId)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})